<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>输出文件指针处的所有剩余数据</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.fopen.html">« fopen</a></li>
      <li style="float: right;"><a href="function.fputcsv.html">fputcsv »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.filesystem.html">文件系统函数</a></li>
    <li>输出文件指针处的所有剩余数据</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.fpassthru" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">fpassthru</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">fpassthru</span> &mdash; <span class="dc-title">输出文件指针处的所有剩余数据</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.fpassthru-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>fpassthru</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$stream</code></span>): <span class="type">int</span></div>

  <p class="para rdfs-comment">
   将给定的文件指针从当前的位置读取到 EOF 并把结果写到输出缓冲区。
  </p>
  <p class="para">
   如果已经向文件写入数据，就必须调用 <span class="function"><a href="function.rewind.html" class="function">rewind()</a></span>
   来将文件指针指向文件头。
  </p>
  <p class="para">
   如果既不修改文件也不在特定位置检索，只想将文件的内容下载到输出缓冲区，应该使用
   <span class="function"><a href="function.readfile.html" class="function">readfile()</a></span>，这样可以省去
   <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> 调用。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.fpassthru-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">stream</code></dt>

     <dd>

      <p class="para">文件指针必须是有效的，必须指向由
<span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> 或 <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span> 成功打开的文件(并还未由 <span class="function"><a href="function.fclose.html" class="function">fclose()</a></span> 关闭)。</p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.fpassthru-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回从 <code class="parameter">stream</code>
   读取并传递到输出的字符数量。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.fpassthru-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2177">
    <p><strong>示例 #1 对二进制文件使用 <span class="function"><strong>fpassthru()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;以二进制格式打开文件<br /></span><span style="color: #0000BB">$name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'./img/ok.png'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'rb'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;发送合适的报头<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type:&nbsp;image/png"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Length:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">filesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;发送图片并终止脚本<br /></span><span style="color: #0000BB">fpassthru</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />exit;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.fpassthru-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    当在 Windows
    系统中将 <span class="function"><strong>fpassthru()</strong></span>
    用于二进制文件，要确保在用
    <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span>
    打开文件时在 mode 中附加了
    <code class="literal">b</code> 来将文件以二进制方式打开。
   </p>
   <p class="para">
    鼓励在处理二进制文件时使用
    <code class="literal">b</code>
    标志，即使系统并不需要，这样可以使脚本的移植性更好。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.fpassthru-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.readfile.html" class="function" rel="rdfs-seeAlso">readfile()</a> - 输出文件</span></li>
    <li class="member"><span class="function"><a href="function.fopen.html" class="function" rel="rdfs-seeAlso">fopen()</a> - 打开文件或者 URL</span></li>
    <li class="member"><span class="function"><a href="function.popen.html" class="function" rel="rdfs-seeAlso">popen()</a> - 打开进程文件指针</span></li>
    <li class="member"><span class="function"><a href="function.fsockopen.html" class="function" rel="rdfs-seeAlso">fsockopen()</a> - 打开 Internet 或者 Unix 套接字连接</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>